public class Main {
    int area, a, b;
    int[] dx = {0, 0, 1, -1};
    int[] dy = {1, -1, 0, 0};
    public int maxAreaOfIsland(int[][] grid) {
        a = grid.length;
        b = grid[0].length;
        for(int i = 0; i < a; i++) {
            for(int j = 0; j < b; j++) {
                if(grid[i][j] == 1) {
                    dfs(grid, i, j, 1);
                }
            }
        }
        return area;
    }
    void dfs(int[][] grid, int i, int j, int path) {
        area = Math.max(area, path);
        grid[i][j] = 0;
        for(int k = 0; k < 4; k++) {
            int x = i + dx[k], y = j + dy[k];
            if(x >= 0 && x < a && y >= 0 && y < b && grid[x][y] == 1) {
                dfs(grid, x, y, path + 1);
            }
        }
    }
    public static void main(String[] args) {
        Main m = new Main();
        int[][] arr = {
                {0,0,1,0,0,0,0,1,0,0,0,0,0},
                {0,0,0,0,0,0,0,1,1,1,0,0,0},
                {0,1,1,0,1,0,0,0,0,0,0,0,0},
                {0,1,0,0,1,1,0,0,1,0,1,0,0},
                {0,1,0,0,1,1,0,0,1,1,1,0,0},
                {0,0,0,0,0,0,0,0,0,0,1,0,0},
                {0,0,0,0,0,0,0,1,1,1,0,0,0},
                {0,0,0,0,0,0,0,1,1,0,0,0,0}
        };
        int sum = m.maxAreaOfIsland(arr);
        System.out.println(sum);
    }
}